"""
图像梯度处理：模糊（均值滤波，中值滤波，高斯滤波）
本质是使用卷积核去卷积图像
"""
import cv2
import numpy as np

img = cv2.imread('../data/lena.jpg',0)
cv2.imshow('img',img)

# 中值滤波
median_blur = cv2.medianBlur(img,5)
cv2.imshow('median_blur',median_blur)

# 均值滤波
mean_blur = cv2.blur(img,(3,3))
cv2.imshow('mean_blur',mean_blur)

# 高斯滤波
gaussion_blur = cv2.GaussianBlur(img,(5,5),3)
cv2.imshow('gaussion_blur',gaussion_blur)

# 使用高斯算子和filter2D自定义滤波操作
gaussan_blur = np.array([
    [1, 4, 7, 4, 1],
    [4, 16, 26, 16, 4],
    [7, 26, 41, 26, 7],
    [4, 16, 26, 16, 4],
    [1, 4, 7, 4, 1]], np.float32) / 273

gau_conv = cv2.filter2D(img,
                        -1, # 图像的深度与原图像相同
                        gaussan_blur)
cv2.imshow('gau_conv',gau_conv)

cv2.waitKey()
cv2.destroyAllWindows()